// 挂号操作
<template>
  <div>
    <TopManu
      :thatF="this"
      :signOut="true"
      @handleQuit="$router.go(-1)"
      @handcreate="handcreate"
    ></TopManu>

    <div class="boxs">
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="门诊挂号" name="1">
          <searchB
            :thatF="this"
            :params="params"
            :showAddUpdate="showAddUpdate"
            :activeName="activeName"
            @selectGetList="selectGetList()"
            @resetSearchB="resetSearchB"
            @dialogStatus="dialogStatus()"
          ></searchB>

          <tableB
            :thatF="this"
            :loading="loading"
            :tableTitle="tableTitle1"
            :activeName="activeName"
            :tableData="tableData1"
            @dialogStatus="dialogStatus()"
            @resetSearchB="resetSearchB"
          ></tableB>
        </el-tab-pane>
        <el-tab-pane label="门诊收费" name="2">
          <div class="tabsB">
            <span
              :class="[pay_status == 1 ? 'on' : '']"
              @click="clickPay_status(1)"
            >待支付</span
            >
            <span
              :class="[pay_status == 2 ? 'on' : '']"
              @click="clickPay_status(2)"
            >已支付</span
            >
            <span
              :class="[pay_status == 3 ? 'on' : '']"
              @click="clickPay_status(3)"
            >已退款</span
            >
            <!-- 20211124已作废改成待退费 -->
            <span
              :class="[pay_status == 4 ? 'on' : '']"
              @click="clickPay_status(4)"
            >待退费</span
            >
          </div>

          <searchB
            :params="params"
            :activeName="activeName"
            @search="search()"
            :thatF="this"
          ></searchB>

          <tableB
            :loading="loading"
            :activeName="activeName"
            :thatF="this"
            :tableTitle="tableTitle2"
            :tableData="tableData2"
          ></tableB>
        </el-tab-pane>
      </el-tabs>

      <div>
        <el-pagination
          class="fenye"
          :background="true"
          :current-page="params.page"
          :page-size="params.limit"
          layout="prev, pager, next"
          @current-change="handlePagination"
          :total="pageCount"
        >
        </el-pagination>
      </div>
      <div>
        <el-dialog
          title="新增门诊挂号"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          v-if="showAddUpdate"
          :modal-append-to-body="false"
          :visible.sync="showAddUpdate"
        >
          <addUpdate @dialogStatus="dialogStatus"></addUpdate>
        </el-dialog>
      </div>
      <div>
        <el-dialog
          :title="yibao.title"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          v-if="yibao.show"
          :modal-append-to-body="false"
          :visible.sync="yibao.show"
        >
          <yibao :thatF="this"></yibao>
        </el-dialog>
      </div>
      <div>
        <el-dialog
          :title="bill.title"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          v-if="bill.show"
          :modal-append-to-body="false"
          :visible.sync="bill.show"
        >
          <bill :thatF="this"></bill>
        </el-dialog>
      </div>
      <div>
        <el-dialog
          title="上传费用明细"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          v-if="yibao.show_FeiYong"
          :modal-append-to-body="false"
          :visible.sync="yibao.show_FeiYong"
        >
          <uploadFeiyong :thatF="this"></uploadFeiyong>
        </el-dialog>
        <el-dialog
          title="药房划价"
          :close-on-click-modal="false"
          :destroy-on-close="true"
          v-if="huajia.show"
          :modal-append-to-body="false"
          :visible.sync="huajia.show"
        >
          <huaJia :thatF="this"></huaJia>
        </el-dialog>
      </div>
      <div>
        <!-- <el-dialog
          title="备案"
          :destroy-on-close="true"
          v-if="yibao_show"
          :visible.sync="yibao_show"
          :close-on-click-modal="false"
          width="30%"
          :before-close="
            () => {
              this.yibao_show = !this.yibao_show;
            }
          "
        >
          <yibaoInfo :dialogTitle="dialogTitle" :thatF="this"></yibaoInfo>
        </el-dialog> -->
      </div>
    </div>
  </div>
</template>

<script>
let that;

import TopManu from "@/components/TopMenu";
import searchB from "./common/search";
import addUpdate from "./common/addUpdate";
import uploadFeiyong from "./common/uploadFeiyong";
import tableB from "./common/tableB";
import yibao from "./common/yibao";
import bill from "./common/bill";
import huaJia from "./common/huaJia";

import {mapState, mapActions} from "vuex";
// import $baseBai from "@/utils/baseBai"
export default {
  name: "RegistrationFee",
  data() {
    return {
      huajia: {
        show: false,
      },
      yibao: {
        show: false,

        show_FeiYong: false,
        selectItem: {},
        title: "",
        selectType: "",
        chargeDataArry: [],
      },
      yibao_show: false,
      bill: {
        show: false,
      },
      topmanuArry: [
        {
          class: "icon-guahao-bai",
          name: "挂号设置",
          key: "1",
        },
        {
          class: "icon-paiban-bai",
          name: "医生排班",
          key: "2",
        },
        {
          class: "icon-yb-bai",
          name: "医保对接",
          key: "list",
          menuArry: [
            {name: "门诊挂号", key: "1"},
            // {name:'上传费用明细', key:'2', },
            // {name:'结算', key:'3', },
            {name: "撤销费用明细", key: "6"},
            {name: "撤销挂号", key: "ybRegisterBack"},
            {name: "结算冲正", key: "cz1"},
            {name: "撤销结算冲正", key: "cz2"},
            {name: "下载结算清单", key: "dwon1"},

          ],
        },
        {
          class: "icon-duizhang-bai",
          name: "医保对账",
          key: "list",
          menuArry: [
            {name: "费用结算对总账", key: "bill"},
            {name: "费用结算对明细账", key: "billDetail"},
            {name: "下载结算清单", key: "dwon2"},
          ],
        },
        {
          class: "icon-his_60_pandian",
          name: "慢特病",
          key: "mante",
        },
        {
          class: "icon-huajia-bai",
          name: "药房划价",
          key: "huajia",
        },
        {
          class: "icon-huajia-bai",
          name: "挂号统计",
          key: "guahao_statistics",
        },
      ],

      tableTitle1: this.$baseBai["workstation"]["mzgh"],
      tableTitle2: this.$baseBai["workstation"]["mzsf"],
      tableData1: [],
      tableData2: [],
      loading: false,
      showAddUpdate: false,
      activeName: "1",
      pageCount: 0,
      params: {
        keyword: "",
        patient_no: "",
        member_name: "",
        doctor_dept: "",
        look_type: "",
        status: "",
        page: 1,
        limit: 10,
      },
      pay_status: 1,

      skinTestData: {},
      subjectData: [],
    };
  },

  mounted() {
    this.getList();
    //  this.getdoctorList()
    //  this.getpatientList()
    this.getDeptIndex();
  },
  methods: {
    ...mapActions(["dictBai/getDict_dataDictIndex"]),
    resetSearchB() {
      this.params = {
        keyword: "",
        patient_no: "",
        member_name: "",
        doctor_dept: "",
        look_type: "",
        status: "",
        page: 1,
        limit: 10,
      };
      this.getList();
    },
    handcreate(item) {
      let url = "";
      console.log("item", item);
      switch (item.key) {
        case "1":
          url = "registeRsetting";
          break;
        case "2":
          url = "doctorScheduling";
          break;
        case "huajia":
          return (this.huajia.show = true);
          break;
        case "guahao_statistics":
          url = "guahao_statistics";
          break;
        case "mante":
          this.$router.push({name: "chronicIdiopathicDisease"});
          break;
        default:
          break;
      }
      this.$router.push({name: url});
    },
    //下拉
    handelDropdown(item) {
      console.log(item);
      if (item != "bill" && item != "billDetail") {
        if (!this.yibao.selectItem.id) {
          return this.$message.error("请选择需要医保对接得用户");
        }
        //  if(this.activeName!=2){
        //    if(this.yibao.selectItem.payment!=6){
        //    return this.$message.error('医保结算方式才可以进行此操作')
        //   }
        //  }
      }

      this.yibao.selectType = item;
      console.log("   this.yibao.selectType ",   this.yibao.selectType )
      switch (item) {
        case "1":
          //挂号

          this.yibao.title = "挂号";
          if (
            this.dict_psn_cert_type.length <= 0 &&
            this.dict_naty.length <= 0
          ) {
            return this["dictBai/getDict_dataDictIndex"]({
              group_id: "64,37,13,14,20",
            }).then((res) => {
              this.yibao.show = true;
            });
          } else {
            this.yibao.show = true;
          }

          break;
        case "2":
          this.yibao.show_FeiYong = true;
          break;
        case "3":
          this.yibao.title = "结算";
          if (
            this.dict_psn_cert_type.length <= 0 ||
            this.dict_naty.length <= 0
          ) {
            return this["dictBai/getDict_dataDictIndex"]({
              group_id: "64,37,13,14,20",
            }).then((res) => {
              this.yibao.show = true;
            });
          } else {
            this.yibao.show = true;
          }
          break;
        case "4":
          this.yibao.title = "结算";
          if (
            this.dict_psn_cert_type.length <= 0 ||
            this.dict_naty.length <= 0 ||
            this.yibao_med_type.length <= 0
          ) {
            return this["dictBai/getDict_dataDictIndex"]({
              group_id: "15,67,64,37,13,14,20",
            }).then((res) => {
              this["_API"]
                .getClinic_feeFeeFeeItem({id: this.yibao.selectItem.id})
                .then((res) => {
                  if (res.code == 200) {
                    this.yibao.chargeDataArry = res.data.map((v) => {
                      return {
                        ...v,
                        rx_circ_flag: "2",
                        hosp_appr_flag: "1",
                      };
                    });
                    this["dictBai/getDict_dataDictIndex"]({
                      group_id: "15,67",
                    }).then((res) => {
                      this.yibao.show = true;
                    });
                  }
                });
            });
          } else {
            this.yibao.show = true;
          }

          break;
        case "5":
          this["_API"]
            .getClinic_feeFeeFeeItem({id: this.yibao.selectItem.id})
            .then((res) => {
              if (res.code == 200) {
                this.yibao.chargeDataArry = res.data.map((v) => {
                  return {
                    ...v,
                    rx_circ_flag: "2",
                    hosp_appr_flag: "",
                  };
                });
                this["dictBai/getDict_dataDictIndex"]({
                  group_id: "15,67",
                }).then((res) => {
                  this.yibao.show_FeiYong = true;
                });
              }
            });

          break;
        case "6":
          //撤销
          let d = {
            patient_no: this.yibao.selectItem.patient_no,
            order_number: this.yibao.selectItem.number,
          };
          this["_API"].getregisterBackFeeUpload2(d).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.message,
                type: "success",
              });
              this.params.page = 1;
              this.getList();
            }
          });
          break;
        case "bill":
        case "billDetail":
          if (this.yibao_insutype.length <= 0) {
            return this["dictBai/getDict_dataDictIndex"]({
              group_id: "13",
            }).then((res) => {
              this.bill.show = true;
            });
          } else {
            this.bill.show = true;
          }
          break;

        case "ybRegisterBack":
          //撤销挂号
          let k = {
            patient_no: this.yibao.selectItem.patient_no,
          };
          this["_API"].getregisterYbRegisterBack(k).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.message,
                type: "success",
              });
              this.params.page = 1;
              this.getList();
            }
          });
          break;
        case "cz1":
        case "cz2":
          let d1 = {
            type: item == "cz1" ? 1 : 2,
          };
          if (this.activeName == 1) {
            d1.patient_no = this.yibao.selectItem.patient_no;
          } else if (this.activeName == 2) {
            d1.order_number = this.yibao.selectItem.number;
          }
          let url =
            this.activeName == 1
              ? "getclinic_ybBackRightSettle"
              : "getclinic_ybBackOrderRightSettle";

          this["_API"][url](d1).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.message,
                type: "success",
              });
              this.params.page = 1;
              this.getList();
            }
          });
          break;
        case "dwon1":
          console.log("$http", this.$http);
          let d2 = {
            patient_no: this.yibao.selectItem.patient_no,
          };
          this["_API"].getregisterDownReportForm(d2).then((res) => {
            if (res.code == 200) {
              window.open(this.$http + "/" + res.data.path);
            }
          });

          break;
        case "dwon3":
          console.log("$http", this.$http);
          const sbd4 = {
            patient_no: this.yibao.selectItem.patient_no,
          };
          this["_API"].getclinic_feeSbDownReportForm(sbd4).then((res) => {
            if (res.code == 200) {
              window.open(this.$http + "/" + res.data.path);
            }
          });

          break;
        case "dwon2":
          let d3 = {
            order_number: this.yibao.selectItem.number,
          };
          this["_API"].getclinic_feeDownReportForm(d3).then((res) => {
            if (res.code == 200) {
              window.open(this.$http + "/" + res.data.path);
            }
          });

          break;
        default:
          break;
      }
    },

    getDeptIndex() {
      this["_API"].getDeptIndex().then((res) => {
        if (res.code == 200) {
          this.subjectData = res.data;
        }
      });
    },
    clickPay_status(num) {
      delete this.tableTitle2.pay_time,
        this.tableTitle2.back_time,
        this.tableTitle2.back_amount;

      this.tableTitle2.forEach((v, index) => {
        if (v.prop == "pay_time") {
          this.tableTitle2.splice(index, 1);
        }
      });
      this.tableTitle2.forEach((v, index) => {
        if (v.prop == "back_time") {
          this.tableTitle2.splice(index, 1);
        }
      });
      this.tableTitle2.forEach((v, index) => {
        if (v.prop == "back_amount") {
          this.tableTitle2.splice(index, 1);
        }
      });
      if (num == 2) {
        this.tableTitle2.splice(6, 0, {
          prop: "pay_time",
          label: "支付时间",
        });
      } else if (num == 3) {
        this.tableTitle2.splice(6, 0, {
          prop: "back_time",
          label: "退款时间",
        });
        this.tableTitle2.splice(6, 0, {
          prop: "back_amount",
          label: "退款金额",
        });
      }
      console.log('num', num)
      console.log('this.tableTitle2', this.tableTitle2)
      this.pay_status = num;
      this.params.page = 1;
      this.getClinic_feeFeeIndex();
    },

    dialogStatus(type) {
      this["dictBai/getDict_dataDictIndex"]({group_id: "71,37"}).then(
        (res) => {
          if (type == 2) {
            this.params.page = 1;
            this.getList();
          }
          this.showAddUpdate = !this.showAddUpdate;
        }
      );
    },
    selectGetList() {
      this.params.page = 1;
      this.getList();
    },
    handleClick(tab, event) {
      let t = this;
      this.yibao.selectItem = {};
      this.params = {
        keyword: "",
        patient_no: "",
        member_name: "",
        doctor_dept: "",
        look_type: "",
        status: "",
        page: 1,
        start_time: "",
        limit: 10,
      };

      if (t.activeName == 1) {
        t.topmanuArry[2].menuArry = [
          {name: "门诊挂号", key: "1"},
          // {name:'上传费用明细', key:'2', },
          // {name:'结算', key:'3', },
          {name: "撤销费用明细", key: "6"},
          {name: "撤销挂号", key: "ybRegisterBack"},
          {name: "结算冲正", key: "cz1"},
          {name: "撤销结算冲正", key: "cz2"},
          {name: "下载结算清单", key: "dwon1"},
        ];

        t.tableData1 = [];
        t.params.page = 1;
        t.getList();
      } else if (t.activeName == 2) {
        t.topmanuArry[2].menuArry = [
          {name: "结算", key: "4"},
          // {name:'费用明细上传', key:'5', },
          // {name:'撤销费用明细', key:'6', },
          {name: "结算冲正", key: "cz1"},
          {name: "撤销结算冲正", key: "cz2"},
          {name: "下载结算清单", key: "dwon2"},
          {name: "下载商保清单", key: "dwon3"},
        ];
        t.tableData2 = [];
        t.params.page = 1;
        t.getClinic_feeFeeIndex();
      }
    },
    handlePagination(e) {
      console.log(e);
      this.params.page = e;
      if (this.activeName == "1") {
        this.getList();
      } else if (this.activeName == "2") {
        this.getClinic_feeFeeIndex();
      }
    },

    getList() {
      this.loading = true;

      let d = JSON.parse(JSON.stringify(this.params));

      if (this.params.start_time) {
        d.start_time = this.params.start_time
          .toString()
          .replace(",", "|")
          .toString();
      }

      this["_API"].registerIndex(d).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.tableData1 = res.data.list;
          this.pageCount = res.data.count;
        }
      });
    },
    getClinic_feeFeeIndex() {
      this.loading = true;

      let d = {
        keyword: this.params.keyword,
        pay_status: this.pay_status,
        page: this.params.page,
        limit: this.params.limit,
      };
      if (this.params.start_time) {
        d.start_time = this.params.start_time
          .toString()
          .replace(",", "|")
          .toString();
      }

      this["_API"].getClinic_feeFeeIndex(d).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.tableData2 = res.data.lists;
          this.pageCount = res.data.count;
        }
      });
    },
  },
  computed: {
    ...mapState({
      dict_psn_cert_type: (state) => state.dictBai.dict_psn_cert_type,
      dict_naty: (state) => state.dictBai.dict_naty,
      yibao_med_type: (state) => state.dictBai.yibao_med_type,
      yibao_insutype: (state) => state.dictBai.yibao_insutype,
      dict_member_type: (state) => state.dictBai.dict_member_type,
    }),
  },
  components: {
    TopManu,
    searchB,
    tableB,
    addUpdate,
    yibao,
    uploadFeiyong,
    bill,
    huaJia,
    //  FormInfo
  },
};
</script>

<style lang='scss' scoped>
@import "./index.scss";

/deep/ .el-tabs__item.is-active {
  color: #02bf6b;
}

/deep/ .el-dialog {
  width: 100%;
  margin-top: 0 !important;
  height: 100vh;
}

/deep/ .el-dialog__body {
  overflow: scroll;
  background-color: white;
}

/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #02bf6b;
}

.fenye {
  text-align: right;
  margin-top: 20px;
}

.tabsB {
  margin: 20px 0;

  > span {
    padding: 8px 20px;
    border: 1px solid #e0e0e0;
    font-size: 14px;
  }

  .on {
    color: #02bf6b;
    border: 1px solid #02bf6b;
  }
}
</style>
